package com.wechart.service.manage.impl;


import com.wechart.dao.domain.Acctbindinfo;
import com.wechart.dao.domain.AcctbindinfoCriteria;
import com.wechart.dao.mapper.AcctbindinfoMapper;
import com.wechart.model.ManagerModel;
import com.wechart.service.manage.AcctbindinfoService;
import com.wechart.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service(value = "acctbindinfoService")
public class AcctbindinfoServiceImpl implements AcctbindinfoService {

    @Autowired
    private AcctbindinfoMapper acctbindinfoMapper;

    @Override
    public List<Acctbindinfo> getAcctbindinfo(ManagerModel managerModel) {
        AcctbindinfoCriteria acctbindinfoCriteria=new AcctbindinfoCriteria();
        AcctbindinfoCriteria.Criteria criteria=acctbindinfoCriteria.createCriteria();
        if(StringUtils.isNoNullString(managerModel.getOrgcode())){
            criteria.andOrgcodeEqualTo(StringUtils.getIdFromString(managerModel.getOrgcode()));
        }
//        if(StringUtils.isNoNullString(managerModel.getConsignnumb())){
//            criteria.andConsignnumbEqualTo(managerModel.getConsignnumb());
//        }
        if(StringUtils.isNoNullString(managerModel.getState())){
            criteria.andStateEqualTo(Short.parseShort(managerModel.getState()));
        }
        if (managerModel.getOrgcodelist().size()>0 && !managerModel.getAreacode().equals("3300")){
            criteria.andOrgcodeIn(managerModel.getOrgcodelist());
        }
//        //账户账号
//        if(StringUtils.isNoNullString(managerModel.getAccount())){
//            criteria.andAccountLike(managerModel.getAccount());
//        }
//        //账户开户银行
//        if(StringUtils.isNoNullString(managerModel.getAcctbank())){
//            criteria.andAccountLike(managerModel.getAcctbank());
//        }
        acctbindinfoCriteria.setOrderByClause("workdate asc");
        return acctbindinfoMapper.selectByExample(acctbindinfoCriteria);
    }
    /**
     * 账户绑定信息表插入
     * @param managerModel
     * @return
     */
    @Override
    public int insertAcctbindinfo(ManagerModel managerModel) {
        AcctbindinfoCriteria acctbindinfoCriteria=new AcctbindinfoCriteria();
        Acctbindinfo data = new Acctbindinfo();
//        data.setId(Long.parseLong(managerModel.getId()));
        data.setOrgcode(managerModel.getOrgcode());
//        data.setConsignnumb(managerModel.getConsignnumb());
//        data.setAcctbank(managerModel.getAcctbank());
//        data.setAccount(managerModel.getAccount());
//        data.setAcctclass(Short.parseShort(managerModel.getAcctclass()));
//        data.setBindbank(managerModel.getBindbank());
//        data.setBindacctbank(managerModel.getBindacctbank());
//        data.setBindacct(managerModel.getBindacct());
//        data.setBindclass(Short.parseShort(managerModel.getBindclass()));
//        data.setCustname(managerModel.getCustname());
        data.setAgtid(managerModel.getAgtid());
        data.setCdtrbank(managerModel.getCdtrbank());
        data.setCdtracct(managerModel.getCdtracct());
        data.setCdtrclass(Short.parseShort(managerModel.getCdtrclass()));
        data.setDbtrbank(managerModel.getDbtrbank());
        data.setDbtracct(managerModel.getDbtracct());
        data.setDbtrname(managerModel.getDbtrname());
        data.setDbtrclass(Short.parseShort(managerModel.getDbtrclass()));
        data.setSignplace(managerModel.getSignplace());

        data.setCerttype(managerModel.getCerttype());
        data.setCertcode(managerModel.getCertcode());
        data.setTel(managerModel.getTel());
//        data.setBankcode(managerModel.getBankcode());
        data.setState(Short.parseShort(managerModel.getState()));
        data.setCreatedate(managerModel.getCreatedate());
        data.setWorkdate(managerModel.getWorkdate());
        data.setLastupdate(new Date());
        return acctbindinfoMapper.insertSelective(data);
    }

    /**
     * 账户绑定信息表修改
     * @param managerModel
     * @return
     */
    @Override
    public int modifyAcctbindinfo(ManagerModel managerModel ,String  id) {
        AcctbindinfoCriteria acctbindinfoCriteria=new AcctbindinfoCriteria();
        acctbindinfoCriteria.createCriteria().andIdEqualTo(Long.parseLong(id));
        Acctbindinfo data = new Acctbindinfo();
//        data.setId(Long.parseLong(managerModel.getId()));
        data.setOrgcode(managerModel.getOrgcode());
//        data.setConsignnumb(managerModel.getConsignnumb());
//        data.setAcctbank(managerModel.getAcctbank());
//        data.setAccount(managerModel.getAccount());
//        data.setAcctclass(Short.parseShort(managerModel.getAcctclass()));
//        data.setBindbank(managerModel.getBindbank());
//        data.setBindacctbank(managerModel.getBindacctbank());
//        data.setBindacct(managerModel.getBindacct());
//        data.setBindclass(Short.parseShort(managerModel.getBindclass()));
//        data.setCustname(managerModel.getCustname());
        data.setAgtid(managerModel.getAgtid());
        data.setCdtrbank(managerModel.getCdtrbank());
        data.setCdtracct(managerModel.getCdtracct());
        data.setCdtrclass(Short.parseShort(managerModel.getCdtrclass()));
        data.setDbtrbank(managerModel.getDbtrbank());
        data.setDbtracct(managerModel.getDbtracct());
        data.setDbtrname(managerModel.getDbtrname());
        data.setDbtrclass(Short.parseShort(managerModel.getDbtrclass()));
        data.setSignplace(managerModel.getSignplace());
        data.setCerttype(managerModel.getCerttype());
        data.setCertcode(managerModel.getCertcode());
        data.setTel(managerModel.getTel());
//        data.setBankcode(managerModel.getBankcode());
        data.setState(Short.parseShort(managerModel.getState()));
        data.setCreatedate(managerModel.getCreatedate());
        data.setWorkdate(managerModel.getWorkdate());
        data.setLastupdate(new Date());
        return acctbindinfoMapper.updateByExampleSelective(data,acctbindinfoCriteria);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Override
    public Acctbindinfo getAcctbindinfoById(String  id) {
        AcctbindinfoCriteria acctbindinfoCriteria=new AcctbindinfoCriteria();
        acctbindinfoCriteria.createCriteria().andIdEqualTo(Long.parseLong(id));
        List<Acctbindinfo> data = acctbindinfoMapper.selectByExample(acctbindinfoCriteria);
        if (null!=data) {
            return data.get(0);
        }else{
            return null;
        }
    }
}
